﻿using System;
using System.Collections.Generic;
using System.Linq;
using Backend.JYD.Model;
using Backend.JYD.Model.Cust;

namespace Backend.JYD.EFDAL.DAL
{
    public class CustAssetsDAL : IDAL.Cust.ICustAssets
	{
		#region 查询数据

		/// <summary>
		/// 查询数据
		/// </summary>
        public PageInfo<CustAsset> GetCustAssetByPage(PageInfo page)
		{
			using (JydDataContext db = new JydDataContext())
			{
                IQueryable<CustAsset> query = db.CustAssets;
				//其他条件代码
                return new PageInfo<CustAsset>(page, query);
			}
		}

        /// <summary>
        /// 查询数据
        /// </summary>
        public IList<CustAsset> GetCustAssetByCustNos(IList<string> custNos)
        {
            string[] nos = custNos.ToArray();
            using (JydDataContext db = new JydDataContext())
            {
                IQueryable<CustAsset> query = db.CustAssets.Where(p => nos.Contains(p.CustNo));
                //其他条件代码
                return query.ToList();
            }
        }

		#endregion

		#region 插入数据

		/// <summary>
		/// 插入数据CustBase
		/// </summary>
        public string AddCustAsset(CustAsset info)
		{
			using (JydDataContext db = new JydDataContext())
			{
                db.CustAssets.Add(info);
				db.SaveChanges();
				return info.CustNo;
			}
		}
		#endregion

		#region 修改数据

        public bool UpdateCustAsset(CustAsset info)
        {
            using (JydDataContext db = new JydDataContext())
            {
                var query = db.CustAssets.Where(p => p.CustNo == info.CustNo);
                if (query != null)
                {
                    var temp = query.FirstOrDefault();
                    if (temp != null)
                    {
                        temp.CustNo = info.CustNo;
                        temp.Deposit = info.Deposit;
                        temp.NationalDebt = info.NationalDebt;
                        temp.Rank = info.Rank;
                        temp.SourceId = info.SourceId;
                        temp.TaskId = info.TaskId;
                        temp.TaskDetailId = info.TaskDetailId;

                        return db.SaveChanges() > 0;
                    }
                }
                return false;
            }
        }

		#endregion

	}
}